package com.cwb.controller;

import com.cwb.pojo.Account;
import com.cwb.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 27435
 * @Date 2025/1/323:53
 * @Version 1.0
 */

@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 根据id查询账户信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Account getAccountById(@PathVariable("id") Integer id){
        return accountService.getAccountById(id);
    }

    /**
     * 查询所有账户信息
     * @return
     */
    @GetMapping
    public List<Account> findAll(){
//        System.out.println("*********************" + accountService.findAll());
        return accountService.findAll();
    }

    /**
     * 添加账户信息
     * @param account
     * @return
     */
    @PostMapping
    public int addAccount(Account account){
        return accountService.addAccount(account);
    }

    /**
     * 修改账户信息
     * @param account
     * @return
     */
    @PutMapping
    public int updateAccount(Account account){
        return accountService.updateAccount(account);
    }

    /**
     * 根据id删除账户信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public int deleteAccountById(@PathVariable("id") Integer id){
        return accountService.deleteAccount(id);
    }

}
